﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace sdamarketing.Marketing
{
    public partial class postaveniReklami : osnova1
    {

        DataSet reklami;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            int rId;
            reklamaEditor re = new reklamaEditor();
            int idUser = Int32.Parse(Session["idUser"].ToString());
            reklami = re.getReklamiNaUser(idUser);
            if (Request["rId"] != null)
                rId = Int32.Parse(Request["rId"].ToString());
            else
                rId = 0;
            if (reklami.Tables[0].Rows.Count > 0 && rId < reklami.Tables[0].Rows.Count && rId >=0)
            {
                naslovLink.Text = reklami.Tables[0].Rows[rId]["Naslov"].ToString();

                slikaLink.ImageUrl = reklami.Tables[0].Rows[rId]["SlikaURL"].ToString().Replace("\\", "/");
                slikaLink.NavigateUrl = reklami.Tables[0].Rows[rId]["Link"].ToString().Replace("\\", "/"); 
                
                opisLink.Text = reklami.Tables[0].Rows[rId]["Opis"].ToString();
                idLabel.Text = reklami.Tables[0].Rows[rId]["idReklama"].ToString();
                klikoviLabel.Text = reklami.Tables[0].Rows[rId]["brKlikovi"].ToString();

                nemaLabel.Visible = false;
            }
            else
            {
                naslovLink.Visible = false;
                slikaLink.Visible = false;
                opisLink.Visible = false;
                klikoviLabel.Visible = false;
                patiPosetenaLabel.Visible = false;

                Button1.Enabled = false;
                Button2.Enabled = false;

                nemaLabel.Visible = true;
            }

            if (rId == 0)
            {
                Button1.Enabled = false;
            }
            if (rId == reklami.Tables[0].Rows.Count-1)
            {
                Button2.Enabled = false;
            }
                
                

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Button1.Enabled = true;
            int rId = (Int32.Parse(Request["rId"].ToString())) + 1;
           
            if(rId < reklami.Tables[0].Rows.Count && rId >=0)
            Response.Redirect("postaveniReklami.aspx?rId=" + rId);
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Button2.Enabled = true;
            

            int rId = (Int32.Parse(Request["rId"].ToString())) - 1;
            
            if (rId < reklami.Tables[0].Rows.Count && rId >= 0)
                Response.Redirect("postaveniReklami.aspx?rId=" + rId);
        }
        


   
    }
}
